#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
using pii = pair<int, int>;

const int MAXN = 210;

int n, m;
string s[MAXN];

int sc[MAXN];

bool cmp(pii x, pii y) {
    return (x.first == y.first) ? (x.second < y.second) : (x.first > y.first);
}

bool check(char a, char b) {
    if (a == b) return false;

    if (a == 'G') return b == 'C';
    if (a == 'C') return b == 'P';
    if (a == 'P') return b == 'G';

    return false;
}
int main() {

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= n*2; i++) cin >> s[i];

    for (int i = 0; i < m; i++) {
        for (int j = 1; j+1 <= n*2; j+=2) {
            if (s[j][i] != s[j+1][i]) {
                bool isFirstWin = check(s[j][i], s[j+1][i]);
                if (isFirstWin) sc[j]++;
                else sc[j+1]++;
            }
        }
    }

    vector<pii> rank;
    for (int i = 1; i <= n*2; i++) {
        rank.push_back(make_pair(sc[i], i));
    }

    sort(rank.begin(), rank.end(), cmp);

    for (int i = 0; i < rank.size(); i++) {
        cout << rank[i].first << ',' << rank[i].second << endl;
    }

    return 0;

}